//
//  ZTDevice.h
//  MQTTNetworkTools
//
//  Created by Yahaong on 16/8/3.
//  Copyright © 2016年 yahaong. All rights reserved.
//

#import "ZTTimeOut.h"
#import "MQTTSessionManager.h"
#import "OperationGroup.h"
#import "OperationModel.h"
#import <XAISDK/XAIPKTAck.h>
#import <XAISDK/XAIPKTStatus.h>
#import <XAISDK/XAIPKT.h>
#import <XAISDK/XAIFormatDataCount.h>


@class ZTDevice,OperationGroup;

typedef NS_ENUM(uint8_t, ZTDeviceChannelStatus){
    ZTDeviceChannelStatusOff   = 0,
    ZTDeviceChannelStatusOn   = 1,
    ZTDeviceChannelStatusUnkown    = 0x99
};

typedef NS_ENUM(uint8_t, ZTDeviceStatus){
    ZTDeviceStatusOFFLINE   = 0,
    ZTDeviceStatusONLINE    = 1,
    ZTDeviceStatusSleeping  = 2,
    ZTDeviceStatusUNKOWN    = 0x99
};

typedef NS_ENUM(uint32_t, ZTDeviceType){

    ZTDeviceTypeMobile           = 0x00000001,
    ZTDeviceTypeGateWay          = 0x00010001,
    ZTDeviceTypeOneWaySwitch     = 0x00010011, //单连单火线
    ZTDeviceTypeTwoWaySwitch     = 0x00010012,
    ZTDeviceTypeThreeWaySwitch   = 0x00010013,
    ZTDeviceTypeFourWaySwitch    = 0x00010014,
    ZTDeviceTypeOneWay0Switch    = 0x00010021, //单连零火线
    ZTDeviceTypeTwoWay0Switch    = 0x00010022,
    ZTDeviceTypeThreeWay0Switch  = 0x00010023,
    ZTDeviceTypeFourWay0Switch   = 0x00010024,
    ZTDeviceTypeZTDoorsensor     = 0x00010030,
    ZTDeviceTypeInfraredDetector = 0x00010040,
    ZTDeviceTypeOneWaySocket     = 0x00010081,
    ZTDeviceTypeTwoWaySocket     = 0x00010082,
    ZTDeviceTypeThreeWaySocket   = 0x00010083,
    ZTDeviceTypeFourWaySocket    = 0x00010084,
    ZTDeviceTypeSmoke            = 0x00010090,
    ZTDeviceTypeAir              = 0x000100A0,
    ZTDeviceTypeGAS              = 0x000100B0,
    ZTDeviceTypeFlooding         = 0x000100C0,
    ZTDeviceTypeAlarmkey         = 0x000100D0,
    ZTDeviceTypeLCCamera         = 0x00020010,
    ZTDeviceTypeCurtainSingleTrack = 0x00010071,
    ZTDeviceTypeCurtainDoubleTrack = 0x00010072
};



@interface ZTDevice : ZTTimeOut

@property (atomic, assign) XAITYPELUID luid;
@property (atomic, assign) XAITYPEAPSN apsn;
@property (atomic, assign) ZTDeviceType devType;
@property (atomic, assign) ZTDeviceStatus devStatus;
@property (nullable, atomic, copy)   NSString* name;
@property (nonatomic, assign) uint8_t isAuthority;
@property (nullable, nonatomic, strong) NSMutableArray <OperationGroup *>*operationGroups;

- (instancetype __nullable)initWithApsn:(XAITYPEAPSN)apsn Luid:(XAITYPELUID)luid;
- (instancetype __nullable)initWithApsn:(XAITYPEAPSN)apsn Luid:(XAITYPELUID)luid type:(ZTDeviceType)type;
- (void)reciveStatus:(uint32_t)gatewayApsn
          deviceLuid:(uint64_t )deviceLuid
         triggerApsn:( uint32_t)triggerApsn
         triggerLuid:(uint64_t)triggerLuid
           timestamp:(uint32_t)timestamp
            statusID:(uint8_t)statusID
                data:(XAITLV*__nonnull)data
           isHistory:(BOOL)isHistory;
- (void)reciveStatus:(XAIPKTStatus* __nullable)pktStatus;
- (void)reciveACK:(XAIPKTAck* __nullable)pktAck;
- (BOOL)isSameDay:(NSInteger )time1 date2:(NSInteger)time2;
- (BOOL)compareOpera:(OperationModel* __nullable)operation1 withOpera:(OperationModel* __nullable)operation2;

- (void)updateOperationWithGatewayApsn:(uint32_t)gatewayApsn
                 deviceLuid:(uint64_t )deviceLuid
                triggerApsn:(uint32_t)triggerApsn
                triggerLuid:(uint64_t)triggerLuid
                  timestamp:(uint32_t)timestamp
                  operation:(NSString *__nullable)oper;

- (NSString * __nullable)getRoomName;
- (NSString * __nullable)getDeviceName;
- (NSString * __nullable)originalName;
- (void)setCircuitStatus:(NSUInteger)status which:(NSUInteger)num;
@end
